

if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
  add_library(gtests-companion-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
  target_include_directories(gtests-companion-lib PUBLIC ${GTEST_INCDIR} ${GTEST_INCDIR}/gtest ${GTEST_SRCDIR})
  add_definitions(-DGTESTS)
  set(TESTS_PATH ${COMPANION_SRC_DIRECTORY}/tests)
  set(RADIO_TESTS_PATH ${RADIO_SRC_DIRECTORY}/tests)
  configure_file(${TESTS_PATH}/location.h.in ${CMAKE_CURRENT_BINARY_DIR}/location.h @ONLY)

  include_directories(${CMAKE_CURRENT_BINARY_DIR})

  if(WIN32)
    target_include_directories(gtests-companion-lib PUBLIC ${WIN_INCLUDE_DIRS})
    target_link_libraries(gtests-companion-lib PRIVATE ${WIN_LINK_LIBRARIES})
  endif(WIN32)

  file(GLOB TEST_SRC_FILES ${TESTS_PATH}/*.cpp)

  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 ${WARNING_FLAGS}")

  use_cxx11()  # ensure gnu++11 in CXX_FLAGS with CMake < 3.1

  add_executable(gtests-companion EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h)
  add_dependencies(gtests-companion gtests-companion-lib)
  target_link_libraries(gtests-companion gtests-companion-lib simulation firmwares storage common)
  message(STATUS "Added optional gtests-companion target")
else()
  message(WARNING "WARNING: gtests target will not be available (check that GTEST_INCDIR, GTEST_SRCDIR, and Qt5Widgets are configured).")
endif()
